home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 79 < prev    next >
Text File  |  1996-08-06  |  2KB  |  51 lines

  1. Newsgroups: comp.std.c
  2. Path: phcoms4.seri.philips.nl!panther!baynes
  3. From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes)
  4. Subject: Re: int's and zero
  5. Sender: news@ukpsshp1.serigate.philips.nl (account for localnews)
  6. Message-ID: <DL0CII.F9A@ukpsshp1.serigate.philips.nl>
  7. Date: Thu, 11 Jan 1996 08:20:41 GMT
  8. References: <4cth4e$4q@odin.funcom.no> <4cub1a$jbl@alterdial.UU.NET> <4d0kd3$d8l@sam.inforamp.net>
  9. Organization: Philips Semiconductors, Southampton, UK
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Peter Curran (pcurran@inforamp.net) wrote:
  13. : On 9 Jan 1996 18:09:46 GMT in article <4cub1a$jbl@alterdial.UU.NET>
  14. :     rex@aussie.com (rex@aussie.com) wrote:
  15.  
  16. : >There was considerable debate about whether or not integers could be stored 
  17. : >as BCD, Grey code, or some such, but in the end, we decided that they had to 
  18. : >be stored as binary numbers. And, of course, 2's comp, 1's comp, and signed 
  19. : >magnitude all use all-bits-zero for zero. The only thing that could cause a 
  20. : >problem is for machines/compilers with signed zeros; I think that negative 
  21. : >zero might have some other bit pattern.
  22.  
  23. : I don't think this is the full story.  The *used* bits have to be zero.
  24. : However, there has been agreement that the integers can have "holes" (unused
  25. : bits), and those bits could be required to be non-zero in some architectures, I
  26. : would think. 
  27.  
  28. Also (under as-if) the bits one sees probably only have to look like binary
  29. to operations such as & and <<. For example I think it is possible to
  30. do something like invert the bits as you read/write memory. Consider this
  31. perverse implementation:
  32.     char - normal binary encoding
  33.     int - binary encoding except that bits are inverted when reading/writing
  34.         memory.
  35.  
  36. Thus binary 0000 written as char will look like binary 1111 when read as int.
  37. So 'memset( &i, 0, sizeof(int) )' will not set int 'i' to 0.
  38. However ints can be copied safely by copying them as an array of char.
  39. Provided normal conversion between int and char works to give the expected
  40. arithmetic results I think that this implementation should meet the standard.
  41.  
  42.  
  43. P.S. Was there ever a final ruling over whether UINT_MAX had to be of the
  44. form 2^n-1 ?
  45.  
  46. --
  47. Stephen Baynes                              baynes@mulsoc2.serigate.philips.nl
  48. Philips Semiconductors Ltd
  49. Southampton                                 My views are my own.
  50. United Kingdom
  51.